package com.wip.reportingservice.services.impls;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wip.reportingservice.daos.entities.ClientsTable;
import com.wip.reportingservice.daos.entities.LogsTable;
import com.wip.reportingservice.daos.entities.PagesTable;
import com.wip.reportingservice.daos.interfaces.IClientsDao;
import com.wip.reportingservice.daos.interfaces.ILogsDao;
import com.wip.reportingservice.daos.interfaces.IPagesDao;
import com.wip.reportingservice.services.domains.ListData;
import com.wip.reportingservice.services.interfaces.IDataService;

@Service
public class DataServiceImpl implements IDataService{

	@Autowired
	private IClientsDao clientDao;

	@Autowired
	private IPagesDao pageDao;

	@Autowired
	private ILogsDao logDao;
	
	@Override
	public ListData getAllClients() {
		List<ClientsTable> clients = clientDao.getAll();
		List<String> list = new ArrayList<String>();
		
		for(ClientsTable client:clients)
		{
			list.add(client.getClientName());
			
		}
		
		ListData all = new ListData();
		all.setData(list);
		return all;
		
	}

	@Override
	public ListData getAllPages() {
		List<PagesTable> pages = pageDao.getAll();
		List<String> list = new ArrayList<String>();
		
		for(PagesTable page:pages)
		{
			list.add(page.getPageName());
			
		}
		
		ListData all = new ListData();
		all.setData(list);
		return all;
	}

	@Override
	public ListData getAllLogs() {
		List<LogsTable> logs = logDao.getAll();
		List<String> list = new ArrayList<String>();
		
		for(LogsTable log:logs)
		{
			list.add(log.getLogFileDate().toString());
			
		}
		
		ListData all = new ListData();
		all.setData(list);
		return all;
	}

}
